import { Component, _decorator } from 'cc';

const { ccclass } = _decorator;

@ccclass("DestroyHook")
export class DestroyHook extends Component {
    onDestroy() {
        for (let i = this.m_Hooks.length - 1; i >= 0; --i) {
            this.m_Hooks[i]();
        }
    }

    private m_Hooks: Function[] = []
    addHook(hook: Function) {
        this.m_Hooks.push(hook)
    }
}